using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ProduceBasicData.Api.Application.Command.Supplier;
using ProduceBasicData.Api.DTO;
using ProduceBasicData.ErrorCode;

namespace ProduceBasicData.Api.Controllers.Supplier
{
    /// <summary>
    /// 供应商控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class SupplierController : ControllerBase
    {
        private readonly IMediator mediator;

        public SupplierController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 供应商信息录入接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> CreateSupplier(CreateSupplierCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 供应商信息查询接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiPaging<SupplierDto>> GetSupplier([FromQuery]GetSupplierCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 供应商信息修改接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> UpdateSupplier(UpdateSupplierCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 供应商信息删除接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> DeleteSupplier(DeleteSupplierCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 获取供应商下拉框数据
        /// </summary>
        /// <returns>供应商列表</returns>
        [HttpGet]
        public async Task<ApiResult<List<Domain.Material.SupplierModel>>> GetSupplierDropdown()
        {
            GetSupplierDropdownCommand request = new GetSupplierDropdownCommand();
            return await mediator.Send(request);
        }
    }
}
